//
//  HZZHomeManger.m
//  HZZ_Sb
//
//  Created by 郭晓东 on 2018/1/29.
//  Copyright © 2018年 Hzz. All rights reserved.
//

#import "HZZDiscoverManger.h"

@implementation HZZDiscoverManger


-(DSASubject *)fetchLeftRecommendedType:(NSString *)type;
{
    NSDictionary *parms = @{
                            @"dtype":type,
                            @"dmrole_token":@"test "
                            };
    DSASubject *suject = [DSASubject subject];
    
    __block NSURLSessionDataTask *task =
    [WYWSessionService startGetRequest:nil
                                  path:LeftRecommended
                                params:parms
                               success:^(NSURLSessionDataTask *dataTask, id responseObj) {
                                   
                                   NSData *jsonData = [responseObj[@"data"] dataUsingEncoding:NSUTF8StringEncoding];
                                   
                                   NSArray *dataArray = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
                            
                                   NSError *err;
                                   NSMutableArray *arrModel = [HZZLeftRecommendedModel arrayOfModelsFromDictionaries:dataArray error:&err];
                                   
                                   
                                   [suject sendNext:arrModel];
                                   [suject sendCompleted];
                               }
                               failure:^(NSError *error) {
                                   [suject sendError:error];
                                   [suject sendCompleted];
                               }];
    [suject setDispose:^{
        [task cancel];
        task = nil;
    }];
    return suject;
}



-(DSASubject *)fetchContentImagesRid:(NSString *)rid;
{
    NSDictionary *parms = @{
                            @"rid":rid,
                            @"dmrole_token":@"test "
                            };
    DSASubject *suject = [DSASubject subject];
    
    __block NSURLSessionDataTask *task =
    [WYWSessionService startGetRequest:nil
                                  path:ContentImages
                                params:parms
                               success:^(NSURLSessionDataTask *dataTask, id responseObj) {
                                   
                                   NSData *jsonData = [responseObj[@"data"] dataUsingEncoding:NSUTF8StringEncoding];
                                   
                                   NSArray *dataArray = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
                                   
                                   NSError *err;
                                   NSMutableArray *arrModel = [HZZFigureBedModel arrayOfModelsFromDictionaries:dataArray error:&err];
                                   
                                   
                                   [suject sendNext:arrModel];
                                   [suject sendCompleted];
                               }
                               failure:^(NSError *error) {
                                   [suject sendError:error];
                                   [suject sendCompleted];
                               }];
    [suject setDispose:^{
        [task cancel];
        task = nil;
    }];
    return suject;
}


@end
